package com.qianyitian.hope2.analyzer.controller;


import com.qianyitian.hope2.analyzer.config.Constant;
import com.qianyitian.hope2.analyzer.service.DemarkService;
import com.qianyitian.hope2.analyzer.service.DemarkService4Demo;
import com.qianyitian.hope2.analyzer.service.IReportStorageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class DemarkController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    DemarkService demarkService;

    @Autowired
    DemarkService4Demo demarkService4Demo;

    @Resource(name = "fileSystemStorageService")
    private IReportStorageService reportService;
    public DemarkController() {
    }


    @RequestMapping("/demark/{portfolio}")
    @CrossOrigin
    public String demark(@PathVariable String portfolio, @RequestParam(value = "days2Now", required = false) Integer days2Now) {
        //這裏千萬不能跑基金，因爲太多了
        return demarkService.demark(portfolio, days2Now);
    }


    @RequestMapping("/analysis/demark/selection")
    @CrossOrigin
    public String demark() {
        return reportService.getAnalysis("selection"+ Constant.TYPE_DAILY);
    }

    @RequestMapping("/demark/fund/{portfolio}")
    @CrossOrigin
    public String fundDemark(@PathVariable String portfolio, @RequestParam(value = "days2Now", required = false) Integer days2Now) {
        return demarkService.fundDemark(portfolio, days2Now);
    }

    @CrossOrigin
    @RequestMapping("/demark-backtrack/{code}")
    public String demarkBacktrack(@PathVariable String code, @RequestParam(value = "days2Now", required = false) Integer days2Now, @RequestParam(value = "rehabilitation", required = false) String rehabilitation) {
        return demarkService.demarkBacktrack(code, days2Now, rehabilitation);
    }

    @CrossOrigin
    @RequestMapping("/demark-backtrack-advance")
    public String demarkBacktrackAdvance(@RequestParam(value = "code", required = true)  String code, @RequestParam(value = "endDate", required = false) String endDate, @RequestParam(value = "t2Now", required = false) Integer t2Now, @RequestParam(value = "t", required = true) String t) {
        return demarkService.demarkBacktrack(code,t2Now, "ea", t,endDate);
    }

    @CrossOrigin
    @RequestMapping("/demark-test")
    public String demarkBacktrackAdvanceForTest(@RequestParam(value = "code", required = true)  String code, @RequestParam(value = "tNumber", required = false,defaultValue = "400") Integer tNumber, @RequestParam(value = "t", required = true) String t) {
        return demarkService4Demo.demarkBacktrackForTest(code,tNumber, t);
    }

    @CrossOrigin
    @RequestMapping("/demark-backtrack/weekly/{code}")
    public String demarkBacktrackWeekly(@PathVariable String code, @RequestParam(value = "days2Now", required = false) Integer days2Now, @RequestParam(value = "rehabilitation", required = false) String rehabilitation) {
        return demarkService.demarkBacktrack(code, days2Now, rehabilitation);
    }

    @CrossOrigin
    @RequestMapping("/demark-backtrack/fund/{code}")
    public String fundDemarkBacktrack(@PathVariable String code, @RequestParam(value = "days2Now", required = false) Integer days2Now) {
        return demarkService.fundDemarkBacktrack(code, days2Now);
    }
}
